package com.digitalchina.lxnsy.viewholder;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.entity.FarmAccountsStatisticsVO;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/8/31 11:10
 * 修改备注：
 * ================================================
 */

public class FarmAccountStatisticsHolder extends BaseViewHolder<FarmAccountsStatisticsVO> {

    private ImageView ivImg;
    private TextView tvMoney;
    private TextView tvName;
    private TextView tvNum;
    private ProgressBar pb;


    public FarmAccountStatisticsHolder(ViewGroup parent) {
        super(parent, R.layout.item_farm_acc_statistics);
        ivImg = $(R.id.iv_img);
        tvMoney = $(R.id.tv_money);
        tvName = $(R.id.tv_name);
        tvNum = $(R.id.tv_num);
        pb = $(R.id.pb);
    }

    @Override
    public void setData(FarmAccountsStatisticsVO data) {
        super.setData(data);

        if (data.getAccountTypeCode() != null) {
            for (int i = 0; i < Constant.FARM_ACCOUNT_TYPE_ARRAY.length; i++) {
                if (Constant.FARM_ACCOUNT_TYPE_ARRAY[i].equals(data.getAccountTypeCode())) {
                    ivImg.setImageResource(Constant.FARM_ACCOUNT_IMAGE_ARRAY[i]);
                    break;
                }
            }
        }


        tvMoney.setText("￥" + data.getMoney());

        tvName.setText(data.getAccountTypeName() + "");

        tvNum.setText(data.getProportion() + "");

        int i;
        if(data.getProportion().contains("."))
            i =  Integer.parseInt(data.getProportion().substring(0, data.getProportion().indexOf(".")));
        else
            i =  Integer.parseInt(data.getProportion().substring(0, data.getProportion().indexOf("%")));
        pb.setProgress(i);
    }

}
